<template>
  <div>
 
    <div class="container">

        <div class="item12">

            <div class="item1">
                <mymenu></mymenu>
            </div>

            <div class="item2">
              <p>个人设置</p>
              
               <van-uploader :after-read="onRead2">
                <!-- <van-button icon="plus" type="primary">上传头像</van-button> -->
                <van-image
                  default="点击上传头像"
                  round
                  width="5rem"
                  height="5rem"
                  :src="src"
                ></van-image>
              </van-uploader>
                 <!-- <van-uploader :after-read="onRead2"/> -->
                
            </div>


        </div>

    </div>

  </div>
</template>

<script>
// 导入子组件
import { time } from 'console';
import mymenu from '../components/menu.vue'

export default {
    
 data() {
    return {
      src:localStorage.getItem('avtar')
        

    }



 

  },
  
  components:{
    mymenu
  },
  methods:{
    //上传图片
    onRead2:function(file){
        let data = new FormData()
        data.append('file',file.file)
        data.append('upload','1'); 
        data.append('token',localStorage.getItem('token'))
        
        // 声明文件配置
        const axiosconfig = this.axios.create({withCredentials:false}) 
        axiosconfig({
          method:'post',
          url:this.baseURL+'upload/',
          data:data

        }).then(resp=>{
          console.log('上传头像',resp)
         

          localStorage.setItem('avtar',this.baseURL +  resp.data.filepath) 
          
          if(resp.data.errcode == 0){
            window.location.reload()
            
          }
     
        })

    }

  },
  mounted(){
    
  },
  created(){
     this.src = localStorage.getItem('avtar')

    

  }

}
</script>


<style scoped>
@import url('../assets/style.css');


</style>

